/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view class="container">
		<join-progress :stepInfo="step"></join-progress>

		<form @submit="submitInfo" class="formbox">
			<view class="item">
				<view class="item-name">店铺名称:</view>
				<input class="item-input" name="store_name" v-model="params.store_name" placeholder="请填写店铺名称">

				</input>
			</view>
			<view class="item">
				<view class="item-name">店铺登录名:</view>
				<input class="item-input" name="seller_name" v-model="params.seller_name" placeholder="请填写店铺登录名">

				</input>
			</view>
			<picker @change="selectStoreType" class="item" :range="storeTypes" range-key="name" :value="storeTypesIndex"
			 aria-haspopup="true">
				<view class="item-name">店铺类型:</view>
				<view class="item-input">{{storeTypes[storeTypesIndex]?storeTypes[storeTypesIndex].name:''}}</view>
				<view class="item-img">
					<image class="next_icon" :src="imgUrl+'common/xr_3.png'"  role="img"></image>
				</view>
			</picker>
			<view class="item" @tap="openCategoryModal">
				<view class="item-name">经营类目:</view>
				<view class="item-input">
					{{category}}
				</view>
				<view class="item-img">
					<image class='next_icon' :src="imgUrl+'common/xr_3.png'" ></image>
				</view>
			</view>
			<picker @change="selectStoreCat" v-if="storeCats" class="item last" :range="storeCats" range-key="sc_name" :value="storeCatsIndex" aria-haspopup="true">
				<view class="item-name">店铺分类:</view>
				<view class="item-input">{{storeCats[storeCatsIndex]?storeCats[storeCatsIndex].sc_name:''}}</view>
				<view class="item-img">
					<image class="next_icon" :src="imgUrl+'common/xr_3.png'"  role="img"></image>
				</view>
			</picker>
			<button class="next-btn" form-type="submit" role="button" aria-disabled="false">下一步</button>
		</form>
		<!-- 经营类目弹窗 -->
		<category ref="cate" :hide="ishide" @closeRegionsModal="close"></category>
	</view>
</template>

<script>
	import joinProgress from "@/components/joinProgress/joinProgress.vue";
	import category from "@/components/category/category.vue";
	import {putStoreApply,getStoreClass,getStoreApply} from "@/api/api.js";
	import common from "@/common/common.js";
	import {mapState} from 'vuex';
	import config from "@/api/config";
	export default {
		data() {
			return {
				step: 2, //步骤e
				imgUrl:config.imgUrl,
				ishide:false,
				params:{
					store_name:"",//店铺名称
					seller_name:"",//店铺登录名
					sc_name:"",//店铺分类名称
					sc_id:"",//店铺分类id
					store_type:0,//店铺类型 1旗舰店 2专卖店 3 专营店
					store_class_id_list:"",//经营类目id
				},
				storeTypesIndex:"",//店铺类型 下标
				storeCatsIndex:"",//店铺分类 下标
				storeTypes: [{
						id: 1,
						name: '旗舰店'
					},
					{
						id: 2,
						name: '专卖店'
					},
					{
						id: 3,
						name: '专营店'
					}
				],
				category:"",//类目
				storeCats:null,//店铺分类
			};
		},
		components: {
			joinProgress,
			category
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onShow(){
			
			if(this.hasLogin){
				this.getStoreClass()
				this.getStoreApply()
			}else{
				common.toast("none","请登录",2000)
				
			}
		},
		methods: {
			/*店铺分类*/ 
			getStoreClass(){
				getStoreClass().then(res=>{
					console.log(res)
					this.storeCats=res
				})
			},
			/*选择店铺类型*/
			selectStoreType(e) {
				console.log(e)
				let value=e.detail.value;
				var name=this.storeTypes[value].name
				this.storeTypesIndex=value;
				this.params.store_type=value;
				// console.log(this.params.store_type)
			},
			/*获取店铺信息*/ 
			getStoreApply(){
				getStoreApply().then(res=>{
					console.log(res)
					if(res.store_name){
						this.params.store_name=res.store_name;
						this.params.seller_name=res.seller_name;
						this.params.sc_name=res.sc_name;
						this.params.sc_id=res.sc_id;
						this.params.store_type=res.store_type;
						this.storeTypes.forEach((i,index)=>{
							if(i.id==res.store_type){
								console.log(index)
								this.storeTypesIndex=index
							}
						})
						this.storeCats.forEach((i,index)=>{
							if(i.sc_name==res.sc_name){
								this.storeCatsIndex=index
							}
						})
					}
				})
			},
			/*更新入驻信息*/ 
			putStoreApply(params){
				putStoreApply(params).then(res=>{
					// console.log(res)
					if(res.status==1){
						common.toast("none","提交成功",3000)
						setTimeout(function(){
							uni.navigateTo({
								url:"/pages/newjoin/join3/join3"
							})
						},3000)
					}	
				})
			},
			/*提交下一步*/ 
			submitInfo(){
				if(!this.params.store_name){
					common.toast("none","请输入店铺名称",3000);
					return;
				}
				if(!this.params.seller_name){
					common.toast("none","请输入店铺登录名",3000)
					return;
				}
				if(!this.params.sc_name){
					common.toast("none","请选择店铺分类",2000)
					return;
				}
				if(!this.params.store_type){
					common.toast("none","请选择店铺类型",2000)
					return;
				}
				if(this.params.store_class_id_list==0){
					common.toast("none","请选择经营类目",2000)
					return;
				}
				console.log(this.params)
				this.putStoreApply(this.params)
			},
			/*选择店铺种类*/
			selectStoreCat(e){
				// console.log(e)
				let value=e.detail.value;
				var sc_name=this.storeCats[value].sc_name;
				var sc_id=this.storeCats[value].sc_id;
				this.storeCatsIndex=value;
				this.params.sc_name=sc_name;
				this.params.sc_id=sc_id;
				console.log(sc_id)
			},
			/*打开弹窗*/ 
			openCategoryModal(){
				// console.log(this.$refs.cate)
				this.ishide=true;
			},
			/*监听子组件*/ 
			close(e){
				console.log(e)
				this.ishide=e.ishide
				var arr=e.checkList;
				var category=[];
				var arrClassId=[];
				var storeclassidlist={};
				var categoryText=[]
				if(arr){
					arr.forEach((i,index)=>{
						// console.log()
						category.push(i.split(","))
					})
					
					category.forEach((i,index)=>{
						arrClassId.push(i[0])
						// console.log(i[0])
						// storeclassidlist.storeclassidlist=i[0]
						categoryText.push(i[1])
						
					})
					// console.log(category)
					this.category=categoryText.join(",")
					this.params.store_class_id_list=arrClassId
					// this.params.storeclassidlist=storeclassidlist
					// this.params.storeclassidlist="21"
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.item {
		float: left;
		padding: 0 30rpx;
		width: 100%;
		box-sizing: border-box;
		font-size: 28rpx;
		border-bottom: 1rpx solid #f3f3f3;
		line-height: 100rpx;
		height: 100rpx;
		position: relative;
		background-color: white;
	}

	.item-name {
		float: left;
	}

	.item-input {
		float: left;
		height: 100rpx;
		width: 450rpx;
		margin-left: 20rpx;
		word-break: keep-all;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.arrow {
		position: absolute;
		right: 30rpx;
		width: 32rpx;
		height: 32rpx;
		padding-top: 30rpx;
	}

	.next-btn {
		float: left;
		background-color: #ff3b3b;
		color: white;
		border-radius: 10rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		width: 710rpx;
		font-size: 36rpx;
		height: 90rpx;
		line-height: 90rpx;
	}

	.next_icon {
		width: 32rpx;
		height: 32rpx;
		float: right;
		margin-top: 32rpx;
	}

	.formbox {
		width: 710rpx;
		margin: 0 auto;
		box-sizing: border-box;
		overflow: hidden;
		border-radius: 10rpx;
		margin-top: 20rpx;
	}

	.last {
		border-bottom-right-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}
</style>
